package com.ruoyi.yjgl.service.impl;

import java.util.List;

import com.ruoyi.nysjwh.domain.TbNysjwhNysjlr;
import com.ruoyi.nysjwh.mapper.TbNysjwhNysjlrMapper;
import com.ruoyi.yjgl.domain.TbYjglYjsz;
import com.ruoyi.yjgl.mapper.TbYjglYjszMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.yjgl.mapper.TbYjglBjjlMapper;
import com.ruoyi.yjgl.domain.TbYjglBjjl;
import com.ruoyi.yjgl.service.ITbYjglBjjlService;

/**
 * 报警记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-11-11
 */
@Service
public class TbYjglBjjlServiceImpl implements ITbYjglBjjlService 
{
    @Autowired
    private TbYjglBjjlMapper tbYjglBjjlMapper;
    @Autowired
    private TbNysjwhNysjlrMapper tbNysjwhNysjlrMapper;
    @Autowired
    private TbYjglYjszMapper tbYjglYjszMapper;

    /**
     * 查询报警记录
     * 
     * @param id 报警记录主键
     * @return 报警记录
     */
    @Override
    public TbYjglBjjl selectTbYjglBjjlById(Long id)
    {
        return tbYjglBjjlMapper.selectTbYjglBjjlById(id);
    }

    /**
     * 查询报警记录列表
     * 
     * @param tbYjglBjjl 报警记录
     * @return 报警记录
     */
    @Override
    public List<TbYjglBjjl> selectTbYjglBjjlList(TbYjglBjjl tbYjglBjjl)
    {
        //1.获取预警信息
        List<TbYjglYjsz> yjsz=tbYjglYjszMapper.selectTbYjglYjszList1();
        //2.获取能源录入信息
        for(TbYjglYjsz i:yjsz)
        {
            TbNysjwhNysjlr tbNysjwhNysjlr=tbNysjwhNysjlrMapper.selectTbNysjwhNysjlr(i);
            if(tbNysjwhNysjlr!=null)
            {
                TbYjglBjjl bjjl=new TbYjglBjjl();
                bjjl.setQy(tbNysjwhNysjlr.getQy());
                bjjl.setNylx(tbNysjwhNysjlr.getNylx());
                bjjl.setYjz(i.getYjz());
                bjjl.setJldw(i.getJldw());
                bjjl.setBz(i.getYjxx());
                bjjl.setJkcjz(tbNysjwhNysjlr.getBcds()-tbNysjwhNysjlr.getScds());
                bjjl.setState("异常");
                List<TbYjglBjjl> tbYjglBjjls=tbYjglBjjlMapper.selectTbYjglBjjlList(bjjl);
                if(tbYjglBjjls==null)
                {
                    tbYjglBjjlMapper.insertTbYjglBjjl(bjjl);
                }


            }
        }


        return tbYjglBjjlMapper.selectTbYjglBjjlList(tbYjglBjjl);
    }

    /**
     * 新增报警记录
     * 
     * @param tbYjglBjjl 报警记录
     * @return 结果
     */
    @Override
    public int insertTbYjglBjjl(TbYjglBjjl tbYjglBjjl)
    {
        return tbYjglBjjlMapper.insertTbYjglBjjl(tbYjglBjjl);
    }

    /**
     * 修改报警记录
     * 
     * @param tbYjglBjjl 报警记录
     * @return 结果
     */
    @Override
    public int updateTbYjglBjjl(TbYjglBjjl tbYjglBjjl)
    {
        return tbYjglBjjlMapper.updateTbYjglBjjl(tbYjglBjjl);
    }

    /**
     * 批量删除报警记录
     * 
     * @param ids 需要删除的报警记录主键
     * @return 结果
     */
    @Override
    public int deleteTbYjglBjjlByIds(Long[] ids)
    {
        return tbYjglBjjlMapper.deleteTbYjglBjjlByIds(ids);
    }

    /**
     * 删除报警记录信息
     * 
     * @param id 报警记录主键
     * @return 结果
     */
    @Override
    public int deleteTbYjglBjjlById(Long id)
    {
        return tbYjglBjjlMapper.deleteTbYjglBjjlById(id);
    }

    @Override
    public List<TbYjglBjjl> selectTbYjglBjjlList1() {
        return tbYjglBjjlMapper.selectTbYjglBjjlList1();
    }
}
